﻿using Infrastructures;
using Models;
using Spring.Data.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace RepositoryMySQL
{
    public class DBUtil
    {
        internal DBUtil() { }

        public static void CreateObj<T>(T obj, string strSql)
        {
            IDbParameters para = DBHelper.TemplateMySQL.CreateDbParameters();
            PropertyInfo[] infos = obj.GetType().GetProperties();

            foreach (var item in infos)
                para.Add(item.Name, (DbType)Enum.Parse(typeof(DbType), item.PropertyType.Name)).Value = item.GetValue(obj, null);

            DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strSql, para);
        }
    }
}
